#pragma once

#include "funpl.h"
#include "errors.h"
#include <sstream>

namespace funpl
{

namespace parser
{

/// Parse exception.
struct parse_exception { };

struct parser_state;

/// Skips the current source of errors (to be called from catch).
void skip_error(parser_state &state);

/// Emits a silent parse error.
void silent_error(parser_state &state);
/// Emits a parse error.
void error(parser_state &state, debug::error_code::t code, const char *pMsg);
/// Emits a parse warning.
void warning(parser_state &state, debug::error_code::t code, const char *pMsg);

} // namespace

} // namespace

/// Emits a parse error.
#define FUNPL_PARSE_ERROR(state, code, msg) ::funpl::parser::error(state, code, static_cast<::std::ostringstream&>(::std::ostringstream() << msg).str().c_str())

/// Emits a token error.
#define FUNPL_PARSE_TOKEN_ERROR(state, code, msg) \
	((!state.silent) \
		? ::funpl::parser::error(state, code, static_cast<::std::ostringstream&>(::std::ostringstream() << msg).str().c_str()) \
		: ::funpl::parser::silent_error(state))

/// Emits a parse warning.
#define FUNPL_PARSE_WARNING(state, code, msg) ::funpl::parser::warning(state, code, static_cast<::std::ostringstream&>(::std::ostringstream() << msg).str().c_str())
